#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk

class Window(gtk.Window):
    def __init__(self):
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
        self.set_title("Basic TreeView Example")
        self.set_size_request(200, 200)
        self.connect("delete_event", self.delete_event)

        # create a TreeStore with one string column to use as the model
        self.treestore = gtk.TreeStore(str)

        # add some data now - 4 rows with 3 child rows each
        for parent in range(4):
            piter = self.treestore.append(None, ['parent %i' % parent])
            for child in range(3):
                self.treestore.append(piter, ['child %i of parent %i' %(child, parent)])

        treeiter = self.treestore.get_iter((2))
        treeiter = self.treestore.iter_next(treeiter)
        print(self.treestore.get_path(treeiter))

        childiter = self.treestore.iter_children(treeiter)
        childiter = self.treestore.iter_next(childiter)
        print(self.treestore.get_path(childiter))

        # create the TreeView using treestore
        self.treeview = gtk.TreeView(self.treestore)

        # create the TreeViewColumn to display the data
        self.tvcolumn = gtk.TreeViewColumn('Column 0')

        # add tvcolumn to treeview
        self.treeview.append_column(self.tvcolumn)

        # create a CellRendererText to reder the data
        self.cell = gtk.CellRendererText()

        # add the cell to the tvcolumn and allow it to expand
        self.tvcolumn.pack_start(self.cell, True)

        self.tvcolumn.add_attribute(self.cell, 'text', 0)

        self.treeview.set_search_column(0)

        self.tvcolumn.set_sort_column_id(0)

        self.tvcolumn.set_reorderable(True)

        self.add(self.treeview)

        self.show_all()

    def main(self):
        gtk.main()

    def delete_event(self, widget, event, data=None):
        gtk.main_quit()
        return False

if __name__ == '__main__':
    w = Window()
    w.main()
